package com.xiaoran.springcloud.controller;

import com.xiaoran.springcloud.entitis.CommonResult;
import com.xiaoran.springcloud.entitis.Payment;
import com.xiaoran.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverport;


    @PostMapping("/payment/create")
    public CommonResult  create(@RequestBody Payment payment){
        int result=paymentService.create(payment);
        log.info("插入的结果是：{}xx",result);
        if(result>0){
            return new CommonResult(200,"插入数据库成功,serverport"+serverport,200);
        }else{
            return new CommonResult(404,"插入数据库失败",null);
        }
    }
    @GetMapping("/payment/get/{id}")
    public CommonResult  getPaymentById(@PathVariable("id")int id){
        Payment payment=paymentService.getPaymentById(id);
        log.info("插入的结果是：{}",payment);
        if(payment!=null){
            return new CommonResult(200,"查询成功,serverport:"+serverport,payment);
        }else{
            return new CommonResult(404,"查询失败，没有这个ID"+id,null);
        }
    }
    @GetMapping("/payment/lb")
    public String getPaymentlb(){
        return serverport;
    }


}
